#include <stdio.h>
#include <time.h>
#include <stdlib.h>

void printDashLine(int l) {

    printf("|");
    for (int j = 0; j < l; j++) {
        printf("-");
        printf("-");
        printf("-");
        printf("|");
    }
}

void print() {
    printf("\n");
    printf("   a   b   c   d   e   f   g   h   i   j         a   b   c   d   e   f   g   h   i   j");  
}

bool courseHuman(char tapleComp[10][10], char k[4], bool hitHuman) {

    int a = 0, b = 0;
	do {
	    printf("enter the coordinates: ");
	    scanf("%i %i", &a, &b);
    } while ((tapleComp[a][b] == 'X') || (tapleComp[a][b] == 'O'));
	
	if (tapleComp[a][b] == 'H') {
	    tapleComp[a][b] = 'X';
    } else {
	    tapleComp[a][b] = 'O';
        hitHuman = false;
        } 	  	
	
	return hitHuman;
}

void ras(char tapleHuman[10][10], char u[4], char u2[3], char u3[3], char u4[2], char u5[2], char u6[2], char u7, char u8, char u9, char u10, int r, int p) {
    
    int z = 0, t = 0, y = 0;
    int s = 0;
    int e = 0;
    int b1 = 0;

    while(b1 == 0) {
    s = 0;
    b1++;
////4
        z = rand()%2;
        if (z == 0) {
            t = rand()%7;
            y = rand()%10;

            for(int i = 0; i < 4; i++) {
                if (tapleHuman[t][y] == ' ') {
                    tapleHuman[t][y] = u[i];
                    t++;
                    e++;
                } else {
                     s++;
                     }
            }
        }
        if (z == 1) {
            t = rand()%10;
            y = rand()%7;

            for(int i = 0; i < 4; i++) {
                if (tapleHuman[t][y] == ' ') {
                    tapleHuman[t][y] = u[i];
                    y++;
                } else {
                    s++;
                    }
            }
        } 
////3
        if (s == 0) {
        e = 0;
        z = rand()%2;
        if (z == 0) {
            t = rand()%8;
            y = rand()%10;
            r = t;
			p = y;
			s++;
			
			if (tapleHuman[r - 1][p - 1] == ' ') {
	            if (tapleHuman[r - 1][p] == ' ') {
	                if (tapleHuman[r - 1][p + 1] == ' ') {
	                   if (tapleHuman[r][p + 1] == ' ') {
	                       if (tapleHuman[r][p - 1] == ' ') {
	                           if (tapleHuman[r + 1][p - 1] == ' ') {
	                               if (tapleHuman[r + 1][p + 1] == ' ') {
	                                  if (tapleHuman[r + 2][p - 1] == ' ') {
	                                    if (tapleHuman[r + 2][p + 1] == ' ') {								   
	                                       if (tapleHuman[r + 3][p + 1] == ' ') {
	                                           if (tapleHuman[r + 3][p] == ' ') {
	                                              if (tapleHuman[r + 3][p - 1] == ' ') {
			                                        s = 0;	
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } 
                }
            }				
		
            for(int i = 0; i < 3; i++) {
                if (tapleHuman[t][y] == ' ') {
                    tapleHuman[t][y] = u2[i];
                    t++;
                    e++;
                } else {
                     s++;
                     }
            }
        }
		}
        if (s == 0) {
		if (z == 1) {
            t = rand()%10;
            y = rand()%8;
            r = t;
			p = y;
			s++;
			
			if (tapleHuman[r - 1][p - 1] == ' ') {
	            if (tapleHuman[r][p - 1] == ' ') {
	                if (tapleHuman[r + 1][p - 1] == ' ') {
	                    if (tapleHuman[r - 1][p] == ' ') {
	                       if (tapleHuman[r + 1][p] == ' ') {
	                            if (tapleHuman[r - 1][p + 1] == ' ') {
	                                if  (tapleHuman[r + 1][p + 1] == ' ') {
	                                    if (tapleHuman[r - 1][p + 2] == ' ') {
	                                        if (tapleHuman[r + 1][p + 2] == ' ') {
	                                            if (tapleHuman[r - 1][p + 3] == ' ') {
	                                                if (tapleHuman[r + 1][p + 3] == ' ') {
	                                                    if (tapleHuman[r][p + 3] == ' ') {
			                                                s = 0;
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			
            for(int i = 0; i < 3; i++) {
                if (tapleHuman[t][y] == ' ') {
                    tapleHuman[t][y] = u2[i];
                    y++;
                } else {
                    s++;
                    }
            }
            }
		}
////3
        if (s == 0) {
        e = 0;
        z = rand()%2;
        if (z == 0) {
            t = rand()%8;
            y = rand()%10;
            r = t;
			p = y;
			s++;
			
			if (tapleHuman[r - 1][p - 1] == ' ') {
	            if (tapleHuman[r - 1][p] == ' ') {
	                if (tapleHuman[r - 1][p + 1] == ' ') {
	                   if (tapleHuman[r][p + 1] == ' ') {
	                       if (tapleHuman[r][p - 1] == ' ') {
	                           if (tapleHuman[r + 1][p - 1] == ' ') {
	                               if (tapleHuman[r + 1][p + 1] == ' ') {
	                                  if (tapleHuman[r + 2][p - 1] == ' ') {
	                                    if (tapleHuman[r + 2][p + 1] == ' ') {								   
	                                       if (tapleHuman[r + 3][p + 1] == ' ') {
	                                           if (tapleHuman[r + 3][p] == ' ') {
	                                              if (tapleHuman[r + 3][p - 1] == ' ') {
			                                        s = 0;	
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } 
                }
            }				
		
            for(int i = 0; i < 3; i++) {
                if (tapleHuman[t][y] == ' ') {
                    tapleHuman[t][y] = u3[i];
                    t++;
                    e++;
                } else {
                     s++;
                     }
            }
        }
		}
      if (s == 0) {
	  if (z == 1) {
            t = rand()%10;
            y = rand()%8;
            r = t;
			p = y;
			s++;
			
			if (tapleHuman[r - 1][p - 1] == ' ') {
	            if (tapleHuman[r][p - 1] == ' ') {
	                if (tapleHuman[r + 1][p - 1] == ' ') {
	                    if (tapleHuman[r - 1][p] == ' ') {
	                       if (tapleHuman[r + 1][p] == ' ') {
	                            if (tapleHuman[r - 1][p + 1] == ' ') {
	                                if  (tapleHuman[r + 1][p + 1] == ' ') {
	                                    if (tapleHuman[r - 1][p + 2] == ' ') {
	                                        if (tapleHuman[r + 1][p + 2] == ' ') {
	                                            if (tapleHuman[r - 1][p + 3] == ' ') {
	                                                if (tapleHuman[r + 1][p + 3] == ' ') {
	                                                    if (tapleHuman[r][p + 3] == ' ') {
			                                                s = 0;
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
				
            for(int i = 0; i < 3; i++) {
                if (tapleHuman[t][y] == ' ') {
                    tapleHuman[t][y] = u3[i];
                    y++;
                } else {
                    s++;
                    }
            }
        }
		}
///2
        if (s == 0) {
        e = 0;
        z = rand()%2;
        if (z == 0) {
            t = rand()%9;
            y = rand()%10;
            r = t;
			p = y;
			s++;
			if (tapleHuman[r - 1][p - 1] == ' ') {
	            if (tapleHuman[r - 1][p] == ' ') {
	                if (tapleHuman[r - 1][p + 1] == ' ') {
	                   if (tapleHuman[r][p + 1] == ' ') {
	                       if (tapleHuman[r][p - 1] == ' ') {
	                           if (tapleHuman[r + 1][p - 1] == ' ') {
	                               if (tapleHuman[r + 1][p + 1] == ' ') {
	                                  if (tapleHuman[r + 2][p + 1] == ' ') {
	                                    if (tapleHuman[r + 2][p] == ' ') {
	                                        if (tapleHuman[r + 2][p - 1] == ' ') {
			                                    s = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } 												
			         
            for(int i = 0; i < 2; i++) {
                if (tapleHuman[t][y] == ' ') {
                    tapleHuman[t][y] = u4[i];
                    t++;
                    e++;
                    s++;
                } else {
                     s++;
                     }
            }
        }
		}
		if (s == 0) {
        if (z == 1) {
            t = rand()%10;
            y = rand()%9;
            r = t;
            p = y;
            s++;
                     if (tapleHuman[r - 1][p - 1] == ' ') {
                        if(tapleHuman[r][p - 1] == ' ') {
                            if(tapleHuman[r + 1][p - 1] == ' ') {
                                if(tapleHuman[r - 1][p] == ' ') {
                                    if(tapleHuman[r + 1][p] == ' ') {
                                        if(tapleHuman[r - 1][p + 1] == ' ') {
                                            if( tapleHuman[r + 1][p + 1] == ' ') {
                                                if(tapleHuman[r - 1][p + 2] == ' ') {
                                                    if(tapleHuman[r + 1][p + 2] == ' ') {
                                                        if(tapleHuman[r][p + 2] == ' ') {
                                                            s = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

            for(int i = 0; i < 2; i++) {
                if (tapleHuman[t][y] == ' ') {
                    tapleHuman[t][y] = u4[i];
                    y++;
                } else {
                    s++;
                    }
            }
        }
		}
///2		
        if (s == 0) {
        e = 0;
        z = rand()%2;
        if (z == 0) {
            t = rand()%9;
            y = rand()%10;
            r = t;
			p = y;
			s++;
			if (tapleHuman[r - 1][p - 1] == ' ') {
	            if (tapleHuman[r - 1][p] == ' ') {
	                if (tapleHuman[r - 1][p + 1] == ' ') {
	                   if (tapleHuman[r][p + 1] == ' ') {
	                       if (tapleHuman[r][p - 1] == ' ') {
	                           if (tapleHuman[r + 1][p - 1] == ' ') {
	                               if (tapleHuman[r + 1][p + 1] == ' ') {
	                                  if (tapleHuman[r + 2][p + 1] == ' ') {
	                                    if (tapleHuman[r + 2][p] == ' ') {
	                                        if (tapleHuman[r + 2][p - 1] == ' ') {
			                                    s = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } 												
			          
            for(int i = 0; i < 2; i++) {
                if (tapleHuman[t][y] == ' ') {
                    tapleHuman[t][y] = u5[i];
                    t++;
                    e++;
                    s++;
                } else {
                     s++;
                     }
            }
        }
		}
		if (s == 0) {
        if (z == 1) {
            t = rand()%10;
            y = rand()%9;
            r = t;
            p = y;
            s++;
                     if (tapleHuman[r - 1][p - 1] == ' ') {
                        if(tapleHuman[r][p - 1] == ' ') {
                            if(tapleHuman[r + 1][p - 1] == ' ') {
                                if(tapleHuman[r - 1][p] == ' ') {
                                    if(tapleHuman[r + 1][p] == ' ') {
                                        if(tapleHuman[r - 1][p + 1] == ' ') {
                                            if( tapleHuman[r + 1][p + 1] == ' ') {
                                                if(tapleHuman[r - 1][p + 2] == ' ') {
                                                    if(tapleHuman[r + 1][p + 2] == ' ') {
                                                        if(tapleHuman[r][p + 2] == ' ') {
                                                            s = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

            for(int i = 0; i < 2; i++) {
                if (tapleHuman[t][y] == ' ') {
                    tapleHuman[t][y] = u5[i];
                    y++;
                } else {
                    s++;
                    }
            }
        }
		}
////2
		if (s == 0) {
        e = 0;
        z = rand()%2;
        if (z == 0) {
            t = rand()%9;
            y = rand()%10;
            r = t;
			p = y;
			s++;
			if (tapleHuman[r - 1][p - 1] == ' ') {
	            if (tapleHuman[r - 1][p] == ' ') {
	                if (tapleHuman[r - 1][p + 1] == ' ') {
	                   if (tapleHuman[r][p + 1] == ' ') {
	                       if (tapleHuman[r][p - 1] == ' ') {
	                           if (tapleHuman[r + 1][p - 1] == ' ') {
	                               if (tapleHuman[r + 1][p + 1] = ' ') {
	                                  if (tapleHuman[r + 2][p + 1] == ' ') {
	                                    if (tapleHuman[r + 2][p] == ' ') {
	                                        if (tapleHuman[r + 2][p - 1] == ' ') {
			                                    s = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } 												
			 
			
            for(int i = 0; i < 2; i++) {
                if (tapleHuman[t][y] == ' ') {
                    tapleHuman[t][y] = u6[i];
                    t++;
                    e++;
                    s++;
                } else {
                     s++;
                     }
            }
        }
		}
		if (s == 0) {
        if (z == 1) {
            t = rand()%10;
            y = rand()%9;
            r = t;
            p = y;
            s++;
                    if (tapleHuman[r - 1][p - 1] == ' ') {
                        if(tapleHuman[r][p - 1] == ' ') {
                            if(tapleHuman[r + 1][p - 1] == ' ') {
                                if(tapleHuman[r - 1][p] == ' ') {
                                    if(tapleHuman[r + 1][p] == ' ') {
                                        if(tapleHuman[r - 1][p + 1] == ' ') {
                                            if( tapleHuman[r + 1][p + 1] == ' ') {
                                                if(tapleHuman[r - 1][p + 2] == ' ') {
                                                    if(tapleHuman[r + 1][p + 2] == ' ') {
                                                        if(tapleHuman[r][p + 2] == ' ') {
                                                            s = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

            for(int i = 0; i < 2; i++) {
                if (tapleHuman[t][y] == ' ') {
                    tapleHuman[t][y] = u6[i];
                    y++;
                } else {
                    s++;
                    }
            }
        }
		}
////1
		if (s == 0) {
        t = rand()%10;
        y = rand()%10;
        r = t;
        p = y;		
        s++;
		
			if (tapleHuman[r + 1][p - 1] == ' ') {
	            if (tapleHuman[r + 1][p] == ' ') {
	                if (tapleHuman[r + 1][p + 1] == ' ') {
	                    if (tapleHuman[r][p - 1] == ' ') {
	                        if (tapleHuman[r][p + 1] == ' ') {
	                            if (tapleHuman[r - 1][p - 1] == ' ') {
	                                if (tapleHuman[r - 1][p] == ' ') {
		                               if (tapleHuman[r - 1][p + 1] == ' ') {
									       s = 0;
										   }
										}
									}
								}
							}
						}
					}
				}
		  
        if(tapleHuman[t][y] = ' ') {
            tapleHuman[t][y] = u7;
        } else {
            s++;
            }
		}
////1
		if (s == 0) {
        t = rand()%10;
        y = rand()%10;
        r = t;
        p = y;		
        s++;
		
			if (tapleHuman[r + 1][p - 1] == ' ') {
	            if (tapleHuman[r + 1][p] == ' ') {
	                if (tapleHuman[r + 1][p + 1] == ' ') {
	                    if (tapleHuman[r][p - 1] == ' ') {
	                        if (tapleHuman[r][p + 1] == ' ') {
	                            if (tapleHuman[r - 1][p - 1] == ' ') {
	                                if (tapleHuman[r - 1][p] == ' ') {
		                               if (tapleHuman[r - 1][p + 1] == ' ') {
									       s = 0;
										   }
										}
									}
								}
							}
						}
					}
				}
		             
        if(tapleHuman[t][y] = ' ') {
            tapleHuman[t][y] = u8;
        } else {
            s++;
            }
		}
////1
		if (s == 0) {
        t = rand()%10;
        y = rand()%10;
         r = t;
        p = y;		
        s++;
		
			if (tapleHuman[r + 1][p - 1] == ' ') {
	            if (tapleHuman[r + 1][p] == ' ') {
	                if (tapleHuman[r + 1][p + 1] == ' ') {
	                    if (tapleHuman[r][p - 1] == ' ') {
	                        if (tapleHuman[r][p + 1] == ' ') {
	                            if (tapleHuman[r - 1][p - 1] == ' ') {
	                                if (tapleHuman[r - 1][p] == ' ') {
		                               if (tapleHuman[r - 1][p + 1] == ' ') {
									       s = 0;
										   }
										}
									}
								}
							}
						}
					}
				}
		            
        if(tapleHuman[t][y] = ' ') {
            tapleHuman[t][y] = u9;
        } else {
            s++;
            }
		}
////1
		if (s == 0) {
        t = rand()%10;
        y = rand()%10;
        r = t;
        p = y;		
        s++;
		
			if (tapleHuman[r + 1][p - 1] == ' ') {
	            if (tapleHuman[r + 1][p] == ' ') {
	                if (tapleHuman[r + 1][p + 1] == ' ') {
	                    if (tapleHuman[r][p - 1] == ' ') {
	                        if (tapleHuman[r][p + 1] == ' ') {
	                            if (tapleHuman[r - 1][p - 1] == ' ') {
	                                if (tapleHuman[r - 1][p] == ' ') {
		                               if (tapleHuman[r - 1][p + 1] == ' ') {
									       s = 0;
										   }
										}
									}
								}
							}
						}
					}
				}
		             
        if(tapleHuman[t][y] = ' ') {
            tapleHuman[t][y] = u10;
        } else {
            s++;
            }
		}
////
        if(s != 0) {
            b1 = 0;
            for (int i = 0; i < 10; i++) {
               for (int j = 0; j < 10; j++) {
               tapleHuman[i][j] = ' ';
               }
            }
        } 
    }  
} 

void ras1(char tapleComp[10][10], char k[4], char k2[3], char k3[3], char k4[2], char k5[2], char k6[2], char k7, char k8, char k9, char k10, int r, int p) {
    
    int z = 0, t = 0, y = 0;
    int s = 0;
    int e = 0;
    int b1 = 0;
    while(b1 == 0) {
    s = 0;
    b1++;
////4
        z = rand()%2;
        if (z == 0) {
            t = rand()%7;
            y = rand()%10;

            for(int i = 0; i < 4; i++) {
                if (tapleComp[t][y] == ' ') {
                    tapleComp[t][y] = k[i];
                    t++;
                    e++;
                } else {
                     s++;
                     }
            }
        }
        if (z == 1) {
            t = rand()%10;
            y = rand()%7;

            for(int i = 0; i < 4; i++) {
                if (tapleComp[t][y] == ' ') {
                    tapleComp[t][y] = k[i];
                    y++;
                } else {
                    s++;
                    }
            }
        } 
////3
        if (s == 0) {
        e = 0;
        z = rand()%2;
        if (z == 0) {
            t = rand()%8;
            y = rand()%10;
            r = t;
			p = y;
			s++;
			
			if (tapleComp[r - 1][p - 1] == ' ') {
	            if (tapleComp[r - 1][p] == ' ') {
	                if (tapleComp[r - 1][p + 1] == ' ') {
	                   if (tapleComp[r][p + 1] == ' ') {
	                       if (tapleComp[r][p - 1] == ' ') {
	                           if (tapleComp[r + 1][p - 1] == ' ') {
	                               if (tapleComp[r + 1][p + 1] == ' ') {
	                                  if (tapleComp[r + 2][p - 1] == ' ') {
	                                    if (tapleComp[r + 2][p + 1] == ' ') {								   
	                                       if (tapleComp[r + 3][p + 1] == ' ') {
	                                           if (tapleComp[r + 3][p] == ' ') {
	                                              if (tapleComp[r + 3][p - 1] == ' ') {
			                                        s = 0;	
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } 
                }
            }				
		
            for(int i = 0; i < 3; i++) {
                if (tapleComp[t][y] == ' ') {
                    tapleComp[t][y] = k2[i];
                    t++;
                    e++;
                } else {
                     s++;
                     }
            }
        }
		}
        if (s == 0) {
		if (z == 1) {
            t = rand()%10;
            y = rand()%8;
            r = t;
			p = y;
			s++;
			
			if (tapleComp[r - 1][p - 1] == ' ') {
	            if (tapleComp[r][p - 1] == ' ') {
	                if (tapleComp[r + 1][p - 1] == ' ') {
	                    if (tapleComp[r - 1][p] == ' ') {
	                       if (tapleComp[r + 1][p] == ' ') {
	                            if (tapleComp[r - 1][p + 1] == ' ') {
	                                if  (tapleComp[r + 1][p + 1] == ' ') {
	                                    if (tapleComp[r - 1][p + 2] == ' ') {
	                                        if (tapleComp[r + 1][p + 2] == ' ') {
	                                            if (tapleComp[r - 1][p + 3] == ' ') {
	                                                if (tapleComp[r + 1][p + 3] == ' ') {
	                                                    if (tapleComp[r][p + 3] == ' ') {
			                                                s = 0;
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}			
			
            for(int i = 0; i < 3; i++) {
                if (tapleComp[t][y] == ' ') {
                    tapleComp[t][y] = k2[i];
                    y++;
                } else {
                    s++;
                    }
            }
            }
		}
////3
        if (s == 0) {
        e = 0;
        z = rand()%2;
        if (z == 0) {
            t = rand()%8;
            y = rand()%10;
            r = t;
			p = y;
			s++;
			
			if (tapleComp[r - 1][p - 1] == ' ') {
	            if (tapleComp[r - 1][p] == ' ') {
	                if (tapleComp[r - 1][p + 1] == ' ') {
	                   if (tapleComp[r][p + 1] == ' ') {
	                       if (tapleComp[r][p - 1] == ' ') {
	                           if (tapleComp[r + 1][p - 1] == ' ') {
	                               if (tapleComp[r + 1][p + 1] == ' ') {
	                                  if (tapleComp[r + 2][p - 1] == ' ') {
	                                    if (tapleComp[r + 2][p + 1] == ' ') {								   
	                                       if (tapleComp[r + 3][p + 1] == ' ') {
	                                           if (tapleComp[r + 3][p] == ' ') {
	                                              if (tapleComp[r + 3][p - 1] == ' ') {
			                                        s = 0;	
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } 
                }
            }				
		
            for(int i = 0; i < 3; i++) {
                if (tapleComp[t][y] == ' ') {
                    tapleComp[t][y] = k3[i];
                    t++;
                    e++;
                } else {
                     s++;
                     }
            }
        }
		}
      if (s == 0) {
	  if (z == 1) {
            t = rand()%10;
            y = rand()%8;
            r = t;
			p = y;
			s++;
			
			if (tapleComp[r - 1][p - 1] == ' ') {
	            if (tapleComp[r][p - 1] == ' ') {
	                if (tapleComp[r + 1][p - 1] == ' ') {
	                    if (tapleComp[r - 1][p] == ' ') {
	                       if (tapleComp[r + 1][p] == ' ') {
	                            if (tapleComp[r - 1][p + 1] == ' ') {
	                                if  (tapleComp[r + 1][p + 1] == ' ') {
	                                    if (tapleComp[r - 1][p + 2] == ' ') {
	                                        if (tapleComp[r + 1][p + 2] == ' ') {
	                                            if (tapleComp[r - 1][p + 3] == ' ') {
	                                                if (tapleComp[r + 1][p + 3] == ' ') {
	                                                    if (tapleComp[r][p + 3] == ' ') {
			                                                s = 0;
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}			
			
            for(int i = 0; i < 3; i++) {
                if (tapleComp[t][y] == ' ') {
                    tapleComp[t][y] = k3[i];
                    y++;
                } else {
                    s++;
                    }
            }
        }
		}
///2
        if (s == 0) {
        e = 0;
        z = rand()%2;
        if (z == 0) {
            t = rand()%9;
            y = rand()%10;
            r = t;
			p = y;
			s++;
			if (tapleComp[r - 1][p - 1] == ' ') {
	            if (tapleComp[r - 1][p] == ' ') {
	                if (tapleComp[r - 1][p + 1] == ' ') {
	                   if (tapleComp[r][p + 1] == ' ') {
	                       if (tapleComp[r][p - 1] == ' ') {
	                           if (tapleComp[r + 1][p - 1] == ' ') {
	                               if (tapleComp[r + 1][p + 1] == ' ') {
	                                  if (tapleComp[r + 2][p + 1] == ' ') {
	                                    if (tapleComp[r + 2][p] == ' ') {
	                                        if (tapleComp[r + 2][p - 1] == ' ') {
			                                    s = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } 												
			         
            for(int i = 0; i < 2; i++) {
                if (tapleComp[t][y] == ' ') {
                    tapleComp[t][y] = k4[i];
                    t++;
                    e++;
                    s++;
                } else {
                     s++;
                     }
            }
        }
		}
		if (s == 0) {
        if (z == 1) {
            t = rand()%10;
            y = rand()%9;
            r = t;
            p = y;
            s++;
                     if (tapleComp[r - 1][p - 1] == ' ') {
                        if(tapleComp[r][p - 1] == ' ') {
                            if(tapleComp[r + 1][p - 1] == ' ') {
                                if(tapleComp[r - 1][p] == ' ') {
                                    if(tapleComp[r + 1][p] == ' ') {
                                        if(tapleComp[r - 1][p + 1] == ' ') {
                                            if( tapleComp[r + 1][p + 1] == ' ') {
                                                if(tapleComp[r - 1][p + 2] == ' ') {
                                                    if(tapleComp[r + 1][p + 2] == ' ') {
                                                        if(tapleComp[r][p + 2] == ' ') {
                                                            s = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

            for(int i = 0; i < 2; i++) {
                if (tapleComp[t][y] == ' ') {
                    tapleComp[t][y] = k4[i];
                    y++;
                } else {
                    s++;
                    }
            }
        }
		}
///2		
        if (s == 0) {
        e = 0;
        z = rand()%2;
        if (z == 0) {
            t = rand()%9;
            y = rand()%10;
            r = t;
			p = y;
			s++;
			if (tapleComp[r - 1][p - 1] == ' ') {
	            if (tapleComp[r - 1][p] == ' ') {
	                if (tapleComp[r - 1][p + 1] == ' ') {
	                   if (tapleComp[r][p + 1] == ' ') {
	                       if (tapleComp[r][p - 1] == ' ') {
	                           if (tapleComp[r + 1][p - 1] == ' ') {
	                               if (tapleComp[r + 1][p + 1] == ' ') {
	                                  if (tapleComp[r + 2][p + 1] == ' ') {
	                                    if (tapleComp[r + 2][p] == ' ') {
	                                        if (tapleComp[r + 2][p - 1] == ' ') {
			                                    s = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } 												
			          
            for(int i = 0; i < 2; i++) {
                if (tapleComp[t][y] == ' ') {
                    tapleComp[t][y] = k5[i];
                    t++;
                    e++;
                    s++;
                } else {
                     s++;
                     }
            }
        }
		}
		if (s == 0) {
        if (z == 1) {
            t = rand()%10;
            y = rand()%9;
            r = t;
            p = y;
            s++;
                     if (tapleComp[r - 1][p - 1] == ' ') {
                        if(tapleComp[r][p - 1] == ' ') {
                            if(tapleComp[r + 1][p - 1] == ' ') {
                                if(tapleComp[r - 1][p] == ' ') {
                                    if(tapleComp[r + 1][p] == ' ') {
                                        if(tapleComp[r - 1][p + 1] == ' ') {
                                            if(tapleComp[r + 1][p + 1] == ' ') {
                                                if(tapleComp[r - 1][p + 2] == ' ') {
                                                    if(tapleComp[r + 1][p + 2] == ' ') {
                                                        if(tapleComp[r][p + 2] == ' ') {
                                                            s = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

            for(int i = 0; i < 2; i++) {
                if (tapleComp[t][y] == ' ') {
                    tapleComp[t][y] = k5[i];
                    y++;
                } else {
                    s++;
                    }
            }
        }
		}
////2
		if (s == 0) {
        e = 0;
        z = rand()%2;
        if (z == 0) {
            t = rand()%9;
            y = rand()%10;
            r = t;
			p = y;
			s++;
			if (tapleComp[r - 1][p - 1] == ' ') {
	            if (tapleComp[r - 1][p] == ' ') {
	                if (tapleComp[r - 1][p + 1] == ' ') {
	                   if (tapleComp[r][p + 1] == ' ') {
	                       if (tapleComp[r][p - 1] == ' ') {
	                           if (tapleComp[r + 1][p - 1] == ' ') {
	                               if (tapleComp[r + 1][p + 1] = ' ') {
	                                  if (tapleComp[r + 2][p + 1] == ' ') {
	                                    if (tapleComp[r + 2][p] == ' ') {
	                                        if (tapleComp[r + 2][p - 1] == ' ') {
			                                    s = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } 														 
			
            for(int i = 0; i < 2; i++) {
                if (tapleComp[t][y] == ' ') {
                    tapleComp[t][y] = k6[i];
                    t++;
                    e++;
                    s++;
                } else {
                     s++;
                     }
            }
        }
		}
		if (s == 0) {
        if (z == 1) {
            t = rand()%10;
            y = rand()%9;
            r = t;
            p = y;
            s++;
                    if (tapleComp[r - 1][p - 1] == ' ') {
                        if(tapleComp[r][p - 1] == ' ') {
                            if(tapleComp[r + 1][p - 1] == ' ') {
                                if(tapleComp[r - 1][p] == ' ') {
                                    if(tapleComp[r + 1][p] == ' ') {
                                        if(tapleComp[r - 1][p + 1] == ' ') {
                                            if( tapleComp[r + 1][p + 1] == ' ') {
                                                if(tapleComp[r - 1][p + 2] == ' ') {
                                                    if(tapleComp[r + 1][p + 2] == ' ') {
                                                        if(tapleComp[r][p + 2] == ' ') {
                                                            s = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

            for(int i = 0; i < 2; i++) {
                if (tapleComp[t][y] == ' ') {
                    tapleComp[t][y] = k6[i];
                    y++;
                } else {
                    s++;
                    }
            }
        }
		}
////1
		if (s == 0) {
        t = rand()%10;
        y = rand()%10;
        r = t;
        p = y;		
        s++;
		
			if (tapleComp[r + 1][p - 1] == ' ') {
	            if (tapleComp[r + 1][p] == ' ') {
	                if (tapleComp[r + 1][p + 1] == ' ') {
	                    if (tapleComp[r][p - 1] == ' ') {
	                        if (tapleComp[r][p + 1] == ' ') {
	                            if (tapleComp[r - 1][p - 1] == ' ') {
	                                if (tapleComp[r - 1][p] == ' ') {
		                               if (tapleComp[r - 1][p + 1] == ' ') {
									       s = 0;
										   }
										}
									}
								}
							}
						} X |   |   |   |   |   |   |    1|   | H |   |   | O | O | O |   |   | H |
 |---|---|---|---|---|---|---|---|---|---|     |---|---|---|---|---|---|---|---|---|---|
2|   |   | O | X | O |   |   |   |   |   |    2|   | H | O |   | O | X | O | H |   |   |
 |---|---|---|---|---|---|---|---|---|---|     |---|---|---|---|---|---|---|---|---|---|
3|   |   |   | X
					}
				}
		  
        if(tapleComp[t][y] = ' ') {
            tapleComp[t][y] = k7;
        } else {
            s++;
            }
		}
////1
		if (s == 0) {
        t = rand()%10;
        y = rand()%10;
        r = t;
        p = y;		
        s++;
		
			if (tapleComp[r + 1][p - 1] == ' ') {
	            if (tapleComp[r + 1][p] == ' ') {
	                if (tapleComp[r + 1][p + 1] == ' ') {
	                    if (tapleComp[r][p - 1] == ' ') {
	                        if (tapleComp[r][p + 1] == ' ') {
	                            if (tapleComp[r - 1][p - 1] == ' ') {
	                                if (tapleComp[r - 1][p] == ' ') {
		                               if (tapleComp[r - 1][p + 1] == ' ') {
									       s = 0;
										   }
										}
									}
								}
							}
						}
					}
				}
		             
        if(tapleComp[t][y] = ' ') {
            tapleComp[t][y] = k8;
        } else {
            s++;
            }
		}
////1
		if (s == 0) {
        t = rand()%10;
        y = rand()%10;
         r = t;
        p = y;		
        s++;
		
			if (tapleComp[r + 1][p - 1] == ' ') {
	            if (tapleComp[r + 1][p] == ' ') {
	                if (tapleComp[r + 1][p + 1] == ' ') {
	                    if (tapleComp[r][p - 1] == ' ') {
	                        if (tapleComp[r][p + 1] == ' ') {
	                            if (tapleComp[r - 1][p - 1] == ' ') {
	                                if (tapleComp[r - 1][p] == ' ') {
		                               if (tapleComp[r - 1][p + 1] == ' ') {
									       s = 0;
										   }
										}
									}
								}
							}
						}
					}
				}
		            
        if(tapleComp[t][y] = ' ') {
            tapleComp[t][y] = k9;
        } else {
            s++;
            }
		}
////1
		if (s == 0) {
        t = rand()%10;
        y = rand()%10;
        r = t;
        p = y;		
        s++;
		
			if (tapleComp[r + 1][p - 1] == ' ') {
	            if (tapleComp[r + 1][p] == ' ') {
	                if (tapleComp[r + 1][p + 1] == ' ') {
	                    if (tapleComp[r][p - 1] == ' ') {
	                        if (tapleComp[r][p + 1] == ' ') {
	                            if (tapleComp[r - 1][p - 1] == ' ') {
	                                if (tapleComp[r - 1][p] == ' ') {
		                               if (tapleComp[r - 1][p + 1] == ' ') {
									       s = 0;
										   }
										}
									}
								}
							}
						}
					}
				}
		             
        if(tapleComp[t][y] = ' ') {
            tapleComp[t][y] = k10;
        } else {
            s++;
            }
		}
////
        if(s != 0) {
            b1 = 0;
            for (int i = 0; i < 10; i++) {
               for (int j = 0; j < 10; j++) {
               tapleComp[i][j] = ' ';
               }
            }
        } 
    }  
} 

bool courseComp(char tapleHuman[10][10], bool hitComp, int &a, int &r, int &p, int e, int &direction, int i, int &a1, int &f) {

    int c = 0, d = 0;
 e = 0;
	if (a1 != 0) {
        if (direction == 1) {
		    tapleHuman[r][p] = 'X';
			tapleHuman[r][p - 1] = 'X';
			
			tapleHuman[r - 1][p + 1] = 'O';
			tapleHuman[r][p + 1] = 'O';
			tapleHuman[r + 1][p + 1] = 'O';
			tapleHuman[r - 1][p] = 'O';
			tapleHuman[r + 1][p] = 'O';
			tapleHuman[r - 1][p - 1] = 'O';
			tapleHuman[r + 1][p - 1] = 'O';
			tapleHuman[r + 1][p - 2] = 'O';
			tapleHuman[r][p - 2] = 'O';
			tapleHuman[r - 1][p - 2] = 'O';	
			hitComp = false;
        }
     
	    if (direction == 2) {
	        tapleHuman[r][p] = 'X';
		    tapleHuman[r][p - 1] = 'X';
		    tapleHuman[r][p - 2] = 'X';
		  
	    	tapleHuman[r - 1][p + 1] = 'O';
		    tapleHuman[r][p + 1] = 'O';
		    tapleHuman[r + 1][p + 1] = 'O';
		    tapleHuman[r - 1][p] = 'O';
	    	tapleHuman[r + 1][p] = 'O';
		    tapleHuman[r - 1][p - 1] = 'O';
	     	tapleHuman[r + 1][p - 1] = 'O';
	     	tapleHuman[r - 1][p - 2] = 'O';
	    	tapleHuman[r + 1][p - 2] = 'O';
	    	tapleHuman[r + 1][p - 3] = 'O';
	    	tapleHuman[r][p - 3] = 'O';
	    	tapleHuman[r - 1][p - 3] = 'O';	
			hitComp = false;
	    }
		
		
	    if (direction == 3) {
	        tapleHuman[r][p] = 'X';
		    tapleHuman[r][p - 1] = 'X';
		    tapleHuman[r][p - 2] = 'X';
			tapleHuman[r][p - 3] = 'X';
		  
	    	tapleHuman[r - 1][p + 1] = 'O';
		    tapleHuman[r][p + 1] = 'O';
		    tapleHuman[r + 1][p + 1] = 'O';
		    tapleHuman[r - 1][p] = 'O';
	    	tapleHuman[r + 1][p] = 'O';
		    tapleHuman[r - 1][p - 1] = 'O';
	     	tapleHuman[r + 1][p - 1] = 'O';
	     	tapleHuman[r - 1][p - 2] = 'O';
	    	tapleHuman[r + 1][p - 2] = 'O';
	     	tapleHuman[r - 1][p - 3] = 'O';
	    	tapleHuman[r + 1][p - 3] = 'O';			
	    	tapleHuman[r + 1][p - 4] = 'O';
	    	tapleHuman[r][p - 4] = 'O';
	    	tapleHuman[r - 1][p - 4] = 'O';	
			hitComp = false;
	    }		
	
	    if (direction == 4) {
		    tapleHuman[r][p] = 'X';
            tapleHuman[r - 1][p] = 'X';
			
			tapleHuman[r + 1][p + 1] = 'O';
	        tapleHuman[r + 1][p] = 'O';
	        tapleHuman[r + 1][p - 1] = 'O';
	        tapleHuman[r][p - 1] = 'O';
	        tapleHuman[r][p + 1] = 'O';
	        tapleHuman[r - 1][p + 1] = 'O';
	        tapleHuman[r - 1][p - 1] = 'O';
	        tapleHuman[r - 2][p - 1] = 'O';
	        tapleHuman[r - 2][p] = 'O';
	        tapleHuman[r - 2][p + 1] = 'O';
			hitComp = false;
        }	

	    if (direction == 5) {
		    tapleHuman[r][p] = 'X';
            tapleHuman[r - 1][p] = 'X';
			tapleHuman[r - 2][p] = 'X';
			
		    tapleHuman[r + 1][p + 1] = 'O';
	        tapleHuman[r + 1][p] = 'O';
	        tapleHuman[r + 1][p - 1] = 'O';
	        tapleHuman[r][p - 1] = 'O';
	        tapleHuman[r][p + 1] = 'O';
	        tapleHuman[r - 1][p + 1] = 'O';
	        tapleHuman[r - 1][p - 1] = 'O';
	        tapleHuman[r - 2][p + 1] = 'O';
	        tapleHuman[r - 2][p - 1] = 'O';
	        tapleHuman[r - 3][p - 1] = 'O';
	        tapleHuman[r - 3][p] = 'O';
	        tapleHuman[r - 3][p + 1] = 'O'; 
            hitComp = false;			
        }
		
	    if (direction == 6) {
		    tapleHuman[r][p] = 'X';
            tapleHuman[r - 1][p] = 'X';
			tapleHuman[r - 2][p] = 'X';
			tapleHuman[r - 3][p] = 'X';
			
		    tapleHuman[r + 1][p + 1] = 'O';
	        tapleHuman[r + 1][p] = 'O';
	        tapleHuman[r + 1][p - 1] = 'O';
	        tapleHuman[r][p - 1] = 'O';
	        tapleHuman[r][p + 1] = 'O';
	        tapleHuman[r - 1][p + 1] = 'O';
	        tapleHuman[r - 1][p - 1] = 'O';
	        tapleHuman[r - 2][p + 1] = 'O';
	        tapleHuman[r - 2][p - 1] = 'O';
		    tapleHuman[r - 3][p + 1] = 'O';
	        tapleHuman[r - 3][p - 1] = 'O';
	        tapleHuman[r - 4][p - 1] = 'O';
	        tapleHuman[r - 4][p] = 'O';
	        tapleHuman[r - 4][p + 1] = 'O';  
			hitComp = false;
        }
		
	    if (direction == 7) {
		    tapleHuman[r][p] = 'X';
            tapleHuman[r][p + 1] = 'X';
			
			tapleHuman[r - 1][p - 1] = 'O';
	        tapleHuman[r][p - 1] = 'O';
	        tapleHuman[r + 1][p - 1] = 'O';
	        tapleHuman[r - 1][p] = 'O';
	        tapleHuman[r + 1][p] = 'O';
	        tapleHuman[r - 1][p + 1] = 'O';
	        tapleHuman[r + 1][p + 1] = 'O';
	        tapleHuman[r - 1][p + 2] = 'O';
	        tapleHuman[r + 1][p + 2] = 'O';
	        tapleHuman[r][p + 2] = 'O';
			hitComp = false;
        }
		
	    if (direction == 8) {
		    tapleHuman[r][p] = 'X';
            tapleHuman[r][p + 1] = 'X';
			tapleHuman[r][p + 2] = 'X';
			
		    tapleHuman[r - 1][p - 1] = 'O';
	        tapleHuman[r][p - 1] = 'O';
	        tapleHuman[r + 1][p - 1] = 'O';
	        tapleHuman[r - 1][p] = 'O';
	        tapleHuman[r + 1][p] = 'O';
	        tapleHuman[r - 1][p + 1] = 'O';
	        tapleHuman[r + 1][p + 1] = 'O';
	        tapleHuman[r - 1][p + 2] = 'O';
	        tapleHuman[r + 1][p + 2] = 'O';
	        tapleHuman[r - 1][p + 3] = 'O';
	        tapleHuman[r + 1][p + 3] = 'O';
	        tapleHuman[r][p + 3] = 'O';
			hitComp = false;
        }		
		
	    if (direction == 9) {
		    tapleHuman[r][p] = 'X';
            tapleHuman[r][p + 1] = 'X';
			tapleHuman[r][p + 2] = 'X';
			tapleHuman[r][p + 3] = 'X';
			
		    tapleHuman[r - 1][p - 1] = 'O';
	        tapleHuman[r][p - 1] = 'O';
	        tapleHuman[r + 1][p - 1] = 'O';
	        tapleHuman[r - 1][p] = 'O';
	        tapleHuman[r + 1][p] = 'O';
	        tapleHuman[r - 1][p + 1] = 'O';
	        tapleHuman[r + 1][p + 1] = 'O';
	        tapleHuman[r - 1][p + 2] = 'O';
	        tapleHuman[r + 1][p + 2] = 'O';
			tapleHuman[r - 1][p + 3] = 'O';
	        tapleHuman[r + 1][p + 3] = 'O';
	        tapleHuman[r - 1][p + 4] = 'O';
	        tapleHuman[r + 1][p + 4] = 'O';
	        tapleHuman[r][p + 4] = 'O';
			hitComp = false;
        }	
		
		if (direction == 10) {
		    tapleHuman[r][p] = 'X';
            tapleHuman[r + 1][p] = 'X';
			
		    tapleHuman[r - 1][p - 1] = 'O';
	        tapleHuman[r - 1][p] = 'O';
	        tapleHuman[r - 1][p + 1] = 'O';
	        tapleHuman[r][p + 1] = 'O';
	        tapleHuman[r][p - 1] = 'O';
	        tapleHuman[r + 1][p - 1] = 'O';
	        tapleHuman[r + 1][p + 1] = 'O';
	        tapleHuman[r + 2][p + 1] = 'O';
	        tapleHuman[r + 2][p] = 'O';
	        tapleHuman[r + 2][p - 1] = 'O'; 
			hitComp = false;
        }
		
		if (direction == 11) {
		    tapleHuman[r][p] = 'X';
            tapleHuman[r + 1][p] = 'X';
			tapleHuman[r + 2][p] = 'X';
			
			tapleHuman[r - 1][p - 1] = 'O';
	        tapleHuman[r - 1][p] = 'O';
	        tapleHuman[r - 1][p + 1] = 'O';
	        tapleHuman[r][p + 1] = 'O';
	        tapleHuman[r][p - 1] = 'O';
	        tapleHuman[r + 1][p - 1] = 'O';
	        tapleHuman[r + 1][p + 1] = 'O';
	        tapleHuman[r + 2][p - 1] = 'O';
	        tapleHuman[r + 2][p + 1] = 'O';
	        tapleHuman[r + 3][p + 1] = 'O';
	        tapleHuman[r + 3][p] = 'O';
	        tapleHuman[r + 3][p - 1] = 'O'; 
			hitComp = false;
        }
		
		if (direction == 12) {
		    tapleHuman[r][p] = 'X';
            tapleHuman[r + 1][p] = 'X';
			tapleHuman[r + 2][p] = 'X';
			tapleHuman[r + 3][p] = 'X';
			
			tapleHuman[r - 1][p - 1] = 'O';
	        tapleHuman[r - 1][p] = 'O';
	        tapleHuman[r - 1][p + 1] = 'O';
	        tapleHuman[r][p + 1] = 'O';
	        tapleHuman[r][p - 1] = 'O';
	        tapleHuman[r + 1][p - 1] = 'O';
	        tapleHuman[r + 1][p + 1] = 'O';
	        tapleHuman[r + 2][p - 1] = 'O';
	        tapleHuman[r + 2][p + 1] = 'O';
		    tapleHuman[r + 3][p - 1] = 'O';
	        tapleHuman[r + 3][p + 1] = 'O';
	        tapleHuman[r + 4][p + 1] = 'O';
	        tapleHuman[r + 4][p] = 'O';
	        tapleHuman[r + 4][p - 1] = 'O'; 
			hitComp = false;
        }
		
		if (direction == 13) {
		    tapleHuman[r][p] = 'X';
			
			tapleHuman[r + 1][p - 1] = 'O';
	        tapleHuman[r + 1][p] = 'O';
	        tapleHuman[r + 1][p + 1] = 'O';
	        tapleHuman[r][p - 1] = 'O';
	        tapleHuman[r][p + 1] = 'O';
	        tapleHuman[r - 1][p - 1] = 'O';
	        tapleHuman[r - 1][p] = 'O';
		    tapleHuman[r - 1][p + 1] = 'O';
			hitComp = false;
        }	
	}
	
	if (a != 0) {
	    if (e == 0) {
		    if (tapleHuman[r][p - 1] == 'H') {
			    direction = 1;
				e++;
				a1++;
				if (tapleHuman[r][p - 2] == 'H') {
				    direction = 2;
					e++;
					a1++;
					if (tapleHuman[r][p - 3] == 'H') {
					    direction = 3;
				    	e++;
					    a1++;
					}
				}
			}
		}
		if (e == 0) {
		    if (tapleHuman[r - 1][p] == 'H') {
			    direction = 4;
				e++;
				a1++;
				if (tapleHuman[r - 2][p] == 'H') {
				    direction = 5;
					e++;
					a1++;
					if (tapleHuman[r - 3][p] == 'H') {
					    direction = 6;
					    e++;
					    a1++;
					}
				}
			}
		}   
	    if (e == 0) {
		    if (tapleHuman[r][p + 1] == 'H') {
			    direction = 7;
				e++;
				a1++;
				if (tapleHuman[r][p + 2] == 'H') {
				    direction = 8;
					e++;
					a1++;
					if (tapleHuman[r][p + 3] == 'H') {
					    direction = 9;
					    e++;
						a1++;
					}
				}
			}
		}
		if (e == 0) {
		    if (tapleHuman[r + 1][p] == 'H') {
			    direction = 10;
				e++;
				a1++;
				if (tapleHuman[r + 2][p] == 'H') {
				    direction = 11;
					e++;
					a1++;
					if (tapleHuman[r + 3][p] == 'H') {
				    	direction = 12;
				    	e++;
					    a1++;
					}
				}
			}
		} 
		
		if (e == 0) {
		    direction = 13;
			e++;
			a1++;
		}
	}
	
	if (e == 0) {
        do {
            c = rand()%10;
            d = rand()%10;
        } while ((tapleHuman[c][d] == 'X') || (tapleHuman[c][d] == 'O'));
	    if (tapleHuman[c][d] == 'H') {
	        tapleHuman[c][d] = 'X';
	        a++;
	    	r = c;
	    	p = d;
	    } else {
	        tapleHuman[c][d] = 'O';
	        hitComp = false;
	    }
	}
	return hitComp;
}

bool result(char tapleComp[10][10], char tapleHuman[10][10], bool canPlay) {
    int a = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (tapleHuman[i][j] == 'H') {
                a++;
            }
        }
    }
        
    if (a == 0) {
        canPlay = false;
        printf("Loosing");
        printf("\n");
    }
    a = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (tapleComp[i][j] == 'H') {
                a++;
            }
        }
    }      
        
    if (a == 0) {
        canPlay = false;
        printf("Win");
        printf("\n");
    }
    return canPlay;
}

int main() {

    char tapleComp[10][10];
	char tapleHuman[10][10];
	char tapleComp1[10][10];
	srand(time(NULL));
	
    for (int i = 0; i < 10; i++) {
       for (int j = 0; j < 10; j++) {
           tapleComp[i][j] = ' ';
       }
    }
	for (int i = 0; i < 10; i++) {
       for (int j = 0; j < 10; j++) {
           tapleHuman[i][j] = ' ';
       }
    }
    for (int i = 0; i < 10; i++) {
       for (int j = 0; j < 10; j++) {
           tapleComp1[i][j] = ' ';
       }
    }
    
	int r = 0, p = 0;
	int e = 0, direction = 0, i = 0;
	int a = 0;
	int a1 = 0;
	int f = 0, l = 0, z = 0;
	char k[4], k2[3], k3[3], k4[2], k5[2], k6[2], k7, k8, k9, k10;
	char u[4], u2[3], u3[3], u4[2], u5[2], u6[2], u7, u8, u9, u10;
    bool canPlay = true;
	bool hitHuman = true;
	bool hitComp = true;

	for(int i = 0; i < 4; i++) {
	    k[i] = 'H';
	}
	for(int i = 0; i < 3; i++) {
	    k2[i] = 'H';
	}
	for(int i = 0; i < 3; i++) {
	    k3[i] = 'H';
	}
	for(int i = 0; i < 2; i++) {
	    k4[i] = 'H';
	}
	for(int i = 0; i < 2; i++) {
	    k5[i] = 'H';
	}
	for(int i = 0; i < 2; i++) {
	    k6[i] = 'H';
	}
	
	k7 = 'H';
	k8 = 'H';
	k9 = 'H';
	k10 = 'H';
    
    u7 = 'H';
	u8 = 'H';
	u9 = 'H';
	u10 = 'H';

	for(int i = 0; i < 4; i++) {
	    u[i] = 'H';
	}
	for(int i = 0; i < 3; i++) {
	    u2[i] = 'H';
	}
	for(int i = 0; i < 3; i++) {
	    u3[i] = 'H';
	}
	for(int i = 0; i < 2; i++) {
	    u4[i] = 'H';
	}
	for(int i = 0; i < 2; i++) {
	    u5[i] = 'H';
	}
	for(int i = 0; i < 2; i++) {
	    u6[i] = 'H';
	}
	
    ras (tapleHuman, u, u2, u3, u4, u5, u6, u7, u8, u9, u10, r, p);
    ras1 (tapleComp, k, k2, k3, k4, k5, k6, k7, k8, k9, k10, r, p);
	
	while (canPlay) {
	    hitHuman = true;
		hitComp = true;
		
		while (hitHuman) {
	        hitHuman = courseHuman(tapleComp, k, hitHuman);
	        if (hitHuman) {
			    print();
				printf("\n");
			    printf(" ");
	            printDashLine (10);
                printf("    ");
				printf(" ");
                printDashLine (10);
                printf("\n");
                for (int i = 0; i < 10; i++) {
                    printf("%i|", i);
                    for (int j = 0; j < 10; j++) {
                       if (tapleComp[i][j] == 'H') {
                          printf("   ");
                          printf("|");
                        } else {
                           printf(" %c ", tapleComp[i][j]);
                           printf("|");
                        }
                    }
                   printf("    ");
                   printf("%i|", i);
                   for (int j = 0; j < 10; j++) {
                         printf(" %c ", tapleHuman[i][j]);
                         printf("|");  
                   }
                
                    printf("\n"); 
					printf(" ");
                    printDashLine (10);
                    printf("    ");
					printf(" ");
                    printDashLine (10);
                    printf("\n");
                }
	            printf("\n");
	        }
	    }
		
	    if (canPlay) {
		    while (hitComp) {
	            hitComp = courseComp(tapleHuman, hitComp, a, r, p, e, direction, i, a1, f);
			}
		}
		print();
		printf("\n");
		printf(" ");
		printDashLine (10);
                printf("    ");
				printf(" ");
                printDashLine (10);
                printf("\n");
                for (int i = 0; i < 10; i++) {
                    printf("%i|", i);
                    for (int j = 0; j < 10; j++) {
                       if (tapleComp[i][j] == 'H') {
                          printf("   ");
                          printf("|");
                        } else {
                           printf(" %c ", tapleComp[i][j]);
                           printf("|");
                        }
                    }
                   printf("    ");
                   printf("%i|", i);
                   for (int j = 0; j < 10; j++) {
                         printf(" %c ", tapleHuman[i][j]);
                         printf("|");  
                   }
                
                    printf("\n"); 
					printf(" ");
                    printDashLine (10);
                    printf("    ");
					printf(" ");
                    printDashLine (10);
                    printf("\n");
                }
	            printf("\n");
            canPlay = result(tapleComp, tapleHuman, canPlay);
        a = 0;
		a1 = 0;
		direction = 0;
    }
    
    return 0;
}
